Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / androidApp / src / fdroid / kotlin / org / meshtastic / app / map / AndroidTileSources.kt

Displaying Raw • Download

androidApp/src/fdroid/kotlin/org/meshtastic/app/map/AndroidTileSources.kt renovate/fastlane-2.x-lockfile (056eed64) Text, 4.37 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.app.map

Tff7b72import T7ee787android.app.Activity
Tff7b72import T7ee787android.content.Intent
Tff7b72import T7ee787android.net.Uri
Tff7b72import T7ee787androidx.activity.compose.rememberLauncherForActivityResult
Tff7b72import T7ee787androidx.activity.result.contract.ActivityResultContracts
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.rememberCoroutineScope
Tff7b72import T7ee787androidx.compose.ui.platform.LocalContext
Tff7b72import T7ee787androidx.core.net.toFile
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787org.koin.compose.koinInject
Tff7b72import T7ee787org.meshtastic.core.common.util.safeCatching
Tff7b72import T7ee787org.meshtastic.feature.map.layers.getFileName
Tff7b72import T7ee787org.meshtastic.feature.map.maplibre.component.customRasterBasemaps
Tff7b72import T7ee787org.meshtastic.feature.map.maplibre.style.Basemap
Tff7b72import T7ee787org.meshtastic.feature.map.tiles.CustomTileProviderConfig
Tff7b72import T7ee787org.meshtastic.feature.map.tiles.CustomTileProviderRepository
Tff7b72import T7ee787java.io.File
Tff7b72import T7ee787kotlin.uuid.Uuid

T8b949e/**
* The absolute path of a stored MBTiles archive, or null if it has gone.
*
* `localUri` is a `file://` URI of a copy in app storage, written when the archive was picked, so it resolves to a real
* path. Android is the only platform that supplies this: the others have no file picker wired up yet.
*/
Tff7b72internal Tff7b72fun Td2a8ffandroidTileArchivePathTb4b4b4(Te6edf3localUriTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657String? Tb4b4b4{
Tff7b72val Te6edf3archive Tff7b72= Te6edf3safeCatching Tb4b4b4{ Te6edf3UriTb4b4b4.Te6edf3parseTb4b4b4(Te6edf3localUriTb4b4b4)Tb4b4b4.Te6edf3toFileTb4b4b4(Tb4b4b4) Tb4b4b4}Tb4b4b4.Te6edf3getOrNullTb4b4b4(Tb4b4b4)
Tff7b72return Tff7b72if Tb4b4b4(Te6edf3archive Tff7b72!Tff7b72= Tff7b72null Tff7b72&Tff7b72& Te6edf3archiveTb4b4b4.Te6edf3existsTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3archiveTb4b4b4.Te6edf3absolutePath
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3withTagTb4b4b4(Ta5d6ff"Ta5d6ffCustomBasemapsTa5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffSkipping a local tile source whose archive is goneTa5d6ff" Tb4b4b4}
Tff7b72null
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Opens a picker for an MBTiles archive and stores what it returns as a custom tile source.
*
* The picked archive is copied into app storage first: MapLibre opens an MBTiles file by path, and a document picker
* hands back a `content://` URI into another app's provider.
*/
Tf0883e@Composable
Tff7b72internal Tff7b72fun Td2a8ffrememberMbTilesImportTb4b4b4(Tb4b4b4)Tb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tb4b4b4{
Tff7b72val Te6edf3repositoryTb4b4b4: Te6edf3CustomTileProviderRepository Tff7b72= Te6edf3koinInjectTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3scope Tff7b72= Te6edf3rememberCoroutineScopeTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3context Tff7b72= Te6edf3LocalContextTb4b4b4.Te6edf3current

Tff7b72val Te6edf3picker Tff7b72=
Te6edf3rememberLauncherForActivityResultTb4b4b4(Te6edf3contract Tff7b72= Te6edf3ActivityResultContractsTb4b4b4.Te6edf3StartActivityForResultTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{ Te6edf3result Tff7b72-Tff7b72>
Tff7b72val Te6edf3uri Tff7b72= Te6edf3resultTb4b4b4.Te6edf3dataTff7b72?.Te6edf3data
Tff7b72if Tb4b4b4(Te6edf3resultTb4b4b4.Te6edf3resultCode Tff7b72=Tff7b72= Te6edf3ActivityTb4b4b4.Te6edf3RESULT_OK Tff7b72&Tff7b72& Te6edf3uri Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{
Tff7b72val Te6edf3name Tff7b72= Te6edf3uriTb4b4b4.Te6edf3getFileNameTb4b4b4(Te6edf3contextTb4b4b4)
Tff7b72val Te6edf3stored Tff7b72= Te6edf3importMbTilesTb4b4b4(Te6edf3contextTb4b4b4, Te6edf3uriTb4b4b4, Ta5d6ff"Ta5d6ffmbtiles_Tffd700${Te6edf3UuidTb4b4b4.Te6edf3randomTb4b4b4(Tb4b4b4)Tffd700}Ta5d6ff.mbtilesTa5d6ff"Tb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3stored Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Te6edf3repositoryTb4b4b4.Te6edf3addCustomTileProviderTb4b4b4(
Te6edf3CustomTileProviderConfigTb4b4b4(
Te6edf3name Tff7b72= Te6edf3nameTb4b4b4.Te6edf3substringBeforeLastTb4b4b4(Ta5d6ff'.'Tb4b4b4)Tb4b4b4,
Te6edf3urlTemplate Tff7b72= Ta5d6ff"Ta5d6ff"Tb4b4b4,
Te6edf3localUri Tff7b72= Te6edf3UriTb4b4b4.Te6edf3fromFileTb4b4b4(Te6edf3FileTb4b4b4(Te6edf3storedTb4b4b4)Tb4b4b4)Tb4b4b4.Te6edf3toStringTb4b4b4(Tb4b4b4)Tb4b4b4,
Tb4b4b4)Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Tff7b72return Tb4b4b4{
T8b949e// Any MIME type: providers hand back application/octet-stream for a perfectly good .mbtiles.
Te6edf3pickerTb4b4b4.Te6edf3launchTb4b4b4(
Te6edf3IntentTb4b4b4(Te6edf3IntentTb4b4b4.Te6edf3ACTION_OPEN_DOCUMENTTb4b4b4)Tb4b4b4.Te6edf3apply Tb4b4b4{
Te6edf3addCategoryTb4b4b4(Te6edf3IntentTb4b4b4.Te6edf3CATEGORY_OPENABLETb4b4b4)
Te6edf3type Tff7b72= Ta5d6ff"Ta5d6ff*/*Ta5d6ff"
Tb4b4b4}Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* The user's custom sources with Android's local-archive support wired in.
*
* [customRasterBasemaps] is common and handles URL templates on every platform; this is the one seam Android adds.
*/
Tf0883e@Composable
Tff7b72internal Tff7b72fun Td2a8ffandroidCustomRasterBasemapsTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3ListTff7b72<Te6edf3BasemapTb4b4b4.Te6edf3RasterTff7b72> Tff7b72=
Te6edf3customRasterBasemapsTb4b4b4(Te6edf3resolveLocalArchive Tff7b72= Tff7b72::Te6edf3androidTileArchivePathTb4b4b4)

Served by rngit 1.5.2 - Generated in 0.04s